// 设置cookie
export function setCookie(cname, cvalue, exdays, isDelete) {
  const d = new Date()
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
  const expires = `expires=${d.toGMTString()}`
  document.cookie = `${cname}=${cvalue}; ${expires};`
  if (isDelete) {
    document.cookie = `${cname}=${cvalue}; ${expires};path=/`
  }
  // 全域名全路径通用  不安全
  // document.cookie = `${cname}=${cvalue}; ${expires};path=/`
}

// 获取cookie
export function getCookie(cname) {
  const name = `${cname}=`
  const ca = document.cookie.split(';')
  for (let i = 0; i < ca.length; i++) {
    const c = ca[i].trim()
    if (c.indexOf(name) === 0) {
      return c.substring(name.length, c.length)
    }
  }
  return ''
}

// 删除cookie
export function delCookie(cname) {
  setCookie(cname, null, -1, true)
}
